
package com.caipiao.lottery.lty.handler.impl;

import com.caipiao.lottery.lty.handler.LtyHandler;
import com.caipiao.lottery.lty.message.LtyRequest;
import com.caipiao.lottery.lty.message.LtyResponse;
import com.caipiao.lottery.core.ErrorDef;
import com.caipiao.lottery.lty.message.MessageResponse;
import com.caipiao.lottery.lty.message.bean.LtyMsgBodySHR1000;

import java.util.List;
import java.util.ArrayList;

/**
 * 实现LtyHandler接口，对接收的字符串列表进行处理
 * 统计列表条数并在每个字段前拼接"abs"
 */
public class LtyHandlerSHR1002 implements LtyHandler {

    @Override
    public String DoProcess(LtyRequest ltyReq, LtyResponse ltyResp) throws Exception {
        // 获取请求中的字符串列表
        @SuppressWarnings("unchecked")
        List<String> inputData = (List<String>) ltyReq.bodyMsg;
        LtyMsgBodySHR1000.Req reqBody = (LtyMsgBodySHR1000.Req) ltyReq.bodyMsg;
        LtyMsgBodySHR1000.Resp respBody = new LtyMsgBodySHR1000.Resp();

        // 统计列表条数
        int dataCount = inputData.size();

        // 创建新的列表，每个元素前拼接"abs"
        List<String> processedData = new ArrayList<>();
        for (String item : inputData) {
            processedData.add("abs" + item);
        }

        respBody.result = dataCount+"";
        respBody.resultDesc = processedData+ "";

        // 设置响应体
        ltyResp.bodyMsg = respBody;

        return ErrorDef.SYS_SUCESS;
    }

    /**
     * 响应体类
     */
    public static class RespBody {
        public int dataCount;          // 列表条数
        public List<String> processedData;  // 拼接abs后的列表
    }
}